package AI;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import Actor.Actor;
import Actor.IfaceCharAction;

public class PointToComandConvertor {
	public static List<IfaceCharAction> convert(List<Point> list, Actor actor) {
		List<IfaceCharAction> list1 = new ArrayList<IfaceCharAction>();
		for (int i = 0; i < list.size() - 1; i++) {
			Point curr = list.get(i);
			Point future = list.get(i + 1);
			if (curr.getX() > future.getX()) {
				list1.add(actor.new RightCommand());
			} else if (curr.getX() < future.getX()) {
				list1.add(actor.new LeftCommand());
			} else if (curr.getY() > future.getY()) {
				list1.add(actor.new DownCommand());
			} else if (curr.getY() < future.getY()) {
				list1.add(actor.new UpCommand());
			}
		}
		return list1;

	}
	public static IfaceCharAction getMovObjectDirection(Actor actorAcive, Actor actor) {

		Actor curr = actorAcive;
		Actor future = actor;
		Random ran = new Random();
		if (curr.getX() > future.getX()){
			return actorAcive.new RightCommand();
		} else if (curr.getX() < future.getX()) {
			return actorAcive.new LeftCommand();
		} else if (curr.getX() == future.getX()) {
			return ran.nextBoolean()?actorAcive.new LeftCommand():actorAcive.new RightCommand();
		} else if (curr.getY() > future.getY()) {
			return actorAcive.new DownCommand();
		} else if (curr.getY() < future.getY()) {
			return actorAcive.new UpCommand();
		}else if (curr.getY() == future.getY()) {
			return ran.nextBoolean()?actorAcive.new UpCommand():actorAcive.new DownCommand();
		}
		return null;

	}
}
